package com.mjh.zhujianju.service.party.impl;

import com.livew.framework.base.service.impl.BaseServiceImpl;
import com.livew.framework.utils.XTListUtils;
import com.mjh.zhujianju.dao.party.BuildingEventUsersMapper;
import com.mjh.zhujianju.model.party.BuildingEventUsersEO;
import com.mjh.zhujianju.service.party.BuildingEventUsersService;
import com.mjh.zhujianju.vo.party.BuildingEventUsersVO;
import com.mjh.zhujianju.vo.party.BuildingEventVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuyang
 * @Description: 活动参与人员
 * @date 2018/8/16 23:10
 */
@Service
public class BuildingEventUsersServiceImpl extends BaseServiceImpl<BuildingEventUsersEO> implements BuildingEventUsersService {

    @Autowired
    private BuildingEventUsersMapper buildingEventUsersMapper;

    public BuildingEventUsersServiceImpl(BuildingEventUsersMapper buildingEventUsersMapper) {
        super(buildingEventUsersMapper);
    }

    @Override
    public List<BuildingEventUsersVO> queryBuildingEventUsersVOByEventIds(List<Long> list) {
        return buildingEventUsersMapper.queryBuildingEventUsersVOByEventIds(list);
    }

    @Override
    public String addJoinEvent(BuildingEventUsersEO buildingEventUsersEO) {
        buildingEventUsersEO.setCreateTime(new Date());
        buildingEventUsersMapper.insertSelective(buildingEventUsersEO);
        return "ok";
    }

    @Override
    public Map<Long, Long> getMapTopOne(List<Long> ids) {
        Map<Long, Long> map = new HashMap<Long, Long>();
        if (XTListUtils.isEmpty(ids)) {
            return map;
        }
        List<BuildingEventUsersVO> buildingEventUsersVOS = buildingEventUsersMapper.queryBuildingEventUsersVOByEventIds(ids);
        if(!CollectionUtils.isEmpty(buildingEventUsersVOS)){
            for(BuildingEventUsersVO buildingEventUsersVO : buildingEventUsersVOS){
                Long count = map.get(buildingEventUsersVO.getEventId());
                if(count == null){
                    map.put(buildingEventUsersVO.getEventId(), 1L);
                }else {
                    map.put(buildingEventUsersVO.getEventId(),count+1);
                }
            }

        }
        return map;
    }

    @Override
    public List<BuildingEventUsersEO> selectPagination(BuildingEventUsersEO buildingEventUsersEO) {
        return buildingEventUsersMapper.selectPagination(buildingEventUsersEO);
    }

    @Override
    public List<BuildingEventUsersEO> queryEventUsersEOById(Long userId) {
        return buildingEventUsersMapper.queryBuildingEventUsersByUserId(userId);
    }
}
